package com.cjbdi.util;

public class StringEditor
{
  public static final int MAX_ARRAY_SIZE = 1073741824;
  protected final String _str;
  protected char[] _char_arr;
  protected int _char_arr_offset;
  protected int _char_arr_len;
  
  public StringEditor()
  {
    this._str = null;
  }
  
  public StringEditor(String s)
  {
    this._str = s;
  }
  protected void _initCharArray()
  {
    this._char_arr = this._str.toCharArray();
    this._char_arr_offset = 0;
    this._char_arr_len = this._char_arr.length;
  }
  
  public StringEditor trimAll()
  {
    if (length() == 0) {
      return this;
    }
    if (this._char_arr == null)
    {
      int len = this._str.length();
      for (int i = 0; i < len; i++)
      {
        char ch = this._str.charAt(i);
        if ((ch <= ' ') || (ch == '　'))
        {
          _initCharArray();
          break;
        }
      }
    }
    int p = 0;
    int end = this._char_arr_offset + this._char_arr_len;
    for (int i = this._char_arr_offset; i < end; i++) {
      if ((this._char_arr[i] > ' ') && (this._char_arr[i] != '　'))
      {
        if (i > p) {
          this._char_arr[p] = this._char_arr[i];
        }
        p++;
      }
    }
    this._char_arr_offset = 0;
    this._char_arr_len = p;
    return this;
  }
  public int length()
  {
    if (this._char_arr != null) {
      return this._char_arr_len;
    }
    if (this._str != null) {
      return this._str.length();
    }
    return 0;
  }
  public String toString()
  {
    if (this._char_arr != null)
    {
      if (this._char_arr_len > 0) {
        return new String(this._char_arr, this._char_arr_offset, this._char_arr_len);
      }
      return "";
    }
    if (this._str != null) {
      return this._str;
    }
    return "";
  }
  public static void main(String[] args) {
	  String s="dfffffff   fgrgrgrgr";
	  System.out.println(new StringEditor(s).trimAll().toString());
  }
}
